﻿using System;
using QuailDashboard.View.QuailServiceReference;

namespace QuailDashboard.View.Helpers
{
    /// <summary>
    /// Helps construct the URL for Test help
    /// </summary>
    public class TestHelpUrl
    {
        /// <summary>
        /// Specifies the type of Test url to create
        /// </summary>
        public enum TestHelpUrlTypes
        {
            /// <summary>
            /// it's a test
            /// </summary>
            Test,

            /// <summary>
            /// it's a class
            /// </summary>
            Class,

            /// <summary>
            /// it's a namespace
            /// </summary>
            Namespace
        }

        /// <summary>
        /// Returns the URL for a test class
        /// </summary>
        /// <param name="className">the name of the class</param>
        /// <param name="urlType">the type of the class</param>
        /// <returns>the url for the help</returns>
        public static Uri GetTestHelpUrl(string className, TestHelpUrlTypes urlType)
        {
            //// namespace: http://qahelp/light/html/N_SmokeTests_JobSeeker.htm
            //// class: http://qahelp/light/html/T_SmokeTests_JobSeeker_CreateAccountTest.htm
            //// test: http://qahelp/light/html/M_SmokeTests_JobSeeker_CreateAccountTest_CreateAccount.htm

            var url = "http://qahelp/light";

            if (!string.IsNullOrEmpty(className))
            {
                url += "/html/";

                if (className.IndexOf('.') == -1)
                {
                    url += "R_Project.htm";
                }
                else
                {
                    switch (urlType)
                    {
                        case TestHelpUrlTypes.Test:
                            url += "M";
                            break;
                        case TestHelpUrlTypes.Class:
                            url += "T";
                            break;
                        case TestHelpUrlTypes.Namespace:
                            url += "N";
                            break;
                    }

                    url += "_" + className.Replace(".", "_") + ".htm";
                }
            }

            return new Uri(url, UriKind.Absolute);
        }
    }
}
